﻿<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="../../../assets/docs.css" rel="stylesheet" type="text/css" media="screen" />
<title>MooTools Documentation - Types/String.QueryString</title>
</head>

<body>
  <div class="doc">
    <div class="methods">
			<h4 class="menu-item"><a href="#String">String</a></h4>
			<div class="menu-item"><a href="#String:parseQueryString">parseQueryString</a></div>
			<div class="menu-item"><a href="#String:cleanQueryString">cleanQueryString</a></div>
    </div>
    <div class="l-border r-border span-15 content">
				<h1 id="String"><a href="#String">Type: String</a></h1>

<p class="description">A collection of the String Object prototype methods.</p>

<h2 id="String:parseQueryString"><a href="#String:parseQueryString">String Method: parseQueryString</a></h2>

<p class="description">Turns a querystring into an object of key/value pairs.</p>

<h3>Syntax</h3>

<pre class="javascript">myString.<span class="me1">parseQueryString</span><span class="br0">(</span>decodeKeys, decodeValues<span class="br0">)</span>;
</pre>

<h3>Arguments</h3>

<ol>
<li>decodeKeys - (<em>boolean</em>, optional) if set to <em>false</em>, keys are passed through [decodeURIComponent][]; defaults to <em>true</em>
</li>
<li>decodeValues - (<em>boolean</em>, optional) if set to <em>false</em>, values are passed through [decodeURIComponent][]; defaults to <em>true</em>
</li>
</ol>
<h3>Example</h3>

<pre class="javascript"><span class="st0">"apple=red&amp;lemon=yellow"</span>.<span class="me1">parseQueryString</span><span class="br0">(</span><span class="br0">)</span>;
<span class="co1">//returns { apple: "red", lemon: "yellow }</span>
<span class="kw2">var</span> fruits = <span class="st0">"apple=red&amp;lemon=yellow"</span>.<span class="me1">parseQueryString</span><span class="br0">(</span><span class="br0">)</span>;
<span class="co1">//returns fruits.apple &gt; "red"</span>
</pre>

<h3>Returns</h3>

<ul>
<li>(<em>object</em>) the querystring as key/value pairs</li>
</ul>
<h2 id="String:cleanQueryString"><a href="#String:cleanQueryString">String Method: cleanQueryString</a></h2>

<p class="description">Removes from a query string any keys that have empty values.</p>

<h3>Syntax</h3>

<pre class="javascript">myQueryString.<span class="me1">cleanQueryString</span><span class="br0">(</span><span class="br0">[</span>method<span class="br0">]</span><span class="br0">)</span>;
</pre>

<h3>Arguments</h3>

<ol>
<li>method - (<em>funciton</em>, optional) a method passed to [Array.filter][] that returns true if a key/value set should be included. Defaults to a method that checks that the value is not an empty string.</li>
</ol>
<h3>Example</h3>

<pre class="javascript"><span class="kw2">var</span> cleaned = <span class="st0">"a=b&amp;x=&amp;z=123&amp;e="</span>.<span class="me1">cleanQueryString</span><span class="br0">(</span><span class="br0">)</span>;
<span class="co1">//cleaned = "a=b&amp;z=123"</span>
<span class="kw2">var</span> noNumberValues = <span class="st0">"a=b&amp;x=y&amp;z=123&amp;e="</span>.<span class="me1">cleanQueryString</span><span class="br0">(</span><span class="kw2">function</span><span class="br0">(</span>set<span class="br0">)</span><span class="br0">{</span>
    <span class="co1">//set is "a=b", "x=y", "z=123", "e="</span>
    <span class="kw1">return</span> !set.<span class="me1">split</span><span class="br0">(</span><span class="st0">"="</span><span class="br0">)</span><span class="br0">[</span><span class="nu0">1</span><span class="br0">]</span>.<span class="me1">match</span><span class="br0">(</span><span class="re0">/<span class="br0">[</span><span class="nu0">0</span><span class="nu0">-9</span><span class="br0">]</span>/</span><span class="br0">)</span>;
<span class="br0">}</span><span class="br0">)</span>;
<span class="co1">//noNumberValues = "a=b&amp;x=y&amp;e="</span>
</pre>

<h3>Returns</h3>

<ul>
<li>(<em>string</em>) the string appropriate key/values removed</li>
</ul>

    </div>
  </div>
<script type="text/javascript" src="../../../assets/mootools-core-1.3.js"></script>
<script type="text/javascript" src="../../../assets/mootools-more-smoothscroll.js"></script>
<script type="text/javascript" src="../../../assets/doc-assist.js"></script>
</body>
</html>
